//
//  LABaseKeyValueLabelView.m
//  LYLazizDevelopDemo
//
//  Created by xbn_iMac on 2016/10/27.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LABaseKeyValueLabelView.h"
#import "Masonry.h"


@interface LABaseKeyValueLabelView ()

@property (strong, nonatomic) UILabel *labKey;
@property (strong, nonatomic) UILabel *labValue;

@end

@implementation LABaseKeyValueLabelView

-(void)awakeFromNib {
    [super awakeFromNib];
    
    self.labKey = [self createLabel];
    [self addSubview:self.labKey];
    
    self.labValue = [self createLabel];
    self.labValue.textColor = UIColorFromRGB(0xff7a21, 1);
    [self addSubview:self.labValue];
    
    [self.labKey mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@0);
        make.leading.equalTo(@0);
    }];
    
    [self.labValue mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@0);
        make.leading.equalTo(self.labKey.mas_trailing).offset(3);
    }];
}

- (void)setKey:(NSString*)key andValue:(NSString*)value {
    self.labKey.text = key;
    self.labValue.text = value;
}

-(UILabel*)createLabel {
    UILabel *lab = [[UILabel alloc] init];
    lab.font = [UIFont systemFontOfSize:14];
    lab.textColor = UIColorFromRGB(0x999999, 1);
    return lab;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.backgroundColor = [UIColor clearColor];
}

- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo([self.labKey intrinsicContentSize].height);
        make.trailing.equalTo(self.labValue.mas_trailing);
    }];
}

- (CGSize)intrinsicContentSize {
    return [self.labKey intrinsicContentSize];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
